Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 학생 회원가입 인증 로직 변경 #669

Merged
merged 46 commits into from
Jul 15, 2024

Conversation

kwoo28
Copy link
Contributor

@kwoo28 kwoo28 commented Jul 8, 2024

🔥 연관 이슈

🚀 작업 내용

변경된 로직은 아래와 같이 이루어집니다.

  1. 학생이 회원가입을 하면 Redis에 정보를 10시간동안 저장합니다.
    (회원가입할때 mysql, redis둘다 이메일, 닉네일 중복 검사)

  2. 이메일 인증 시 Redis에서 인증 토큰을 검사합니다.

  3. 인증이 정상적으로 이루어지면 mysql저장 후 redis에서 데이터 삭제합니다.

또한 인증 토큰 관련 오류메시지중 "이미 만료된 토큰입니다.", "이미 인증된 사용자입니다.", "토큰에 해당하는 사용자를 찾을 수 없습니다." 라는 오류메시지 출력을 "유효하지 않는 토큰입니다." 로 간소화했습니다.

Redis관련 이해를 돕기위해 아래와같이 사진으로 과정 첨부합니다.

  1. 회원가입시 Redis저장합니다.
    image
    image

  2. 중복된 이메일로 회원가입시 Redis에서 중복검증합니다.
    image

  3. 회원가입 인증시 Redis에 저장된 데이터를 삭제합니다.
    image
    image

Redis관련작업은 아래와 같은 공식문서에서 참조해서 작업했습니다.
https://docs.spring.io/spring-data/redis/reference/redis/redis-repositories/indexes.html
https://redis.io/docs/latest/integrate/redisom-for-java/

💬 리뷰 중점사항

@kwoo28 kwoo28 self-assigned this Jul 8, 2024
@github-actions github-actions bot added the 기능 새로운 기능을 개발합니다. label Jul 8, 2024
Copy link

github-actions bot commented Jul 8, 2024

Unit Test Results

  29 files    29 suites   2m 31s ⏱️
237 tests 236 ✔️ 1 💤 0
238 runs  237 ✔️ 1 💤 0

Results for commit d436385.

♻️ This comment has been updated with latest results.

Comment on lines +18 to +26
@Id
@Indexed
private String email;

@Indexed
private String authToken;

@Indexed
private String nickname;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@id는 Redis의 StudentTemporaryStatus접두사에서 식별자인 key값을 의미합니다.

@indexed는 필드로부터 데이터를 찾을 수 있게해주는 Secondary 인덱싱을 의미합니다.
email, nickname을 @indexed한 이유는 이메일,닉네임 중복검사하기 위해 사용했으며, authToken을 @indexed한 이유는 토큰 인증을 위해 사용했습니다.

Copy link
Contributor

@duehee duehee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

작성 수고 많으셨습니다~
코멘트 한 번 확인해주세요! 굿굿 :D

@RedisHash(value = "StudentTemporaryStatus")
public class StudentTemporaryStatus {

private static final long CACHE_EXPIRE_SECOND = 60 * 60 * 10L;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

저번 레거시부터 느꼈지만, 굳이 회원가입 인증 토큰을 10시간 보관하는게 괜찮은가 싶네요
10시간동안 안 받을 정도면..🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러게요... 근데 수정하게 된다면 팀 전체 논의사항으로 올려야 할것같네요..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 인증번호를 받는 형식이 아니라 저는 괜찮을 수도 있을 것 같아요
일반적으로 인증번호는 시간을 짧게 하고 저렇게 메일로 보내서 접속하면 인증되게 하는 방식은 엄청 길게 주더라구요
(얼마전에 microsoft 관련해서도 까먹고 있다가 6개월 만에 가서 받았는데 됐음)

Comment on lines 60 to 63
public static StudentTemporaryStatus of(StudentRegisterRequest request, String authToken) {
return new StudentTemporaryStatus(request.email(), authToken, request.nickname(),request.name(), request.password(), request.gender(),
request.isGraduated(), request.department(), request.studentNumber(), request.phoneNumber());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

라인의 상태가..!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오.. 세밀한 캐치 감사합니다


StudentTemporaryStatus save(StudentTemporaryStatus studentTemporaryStatus);

Optional<StudentTemporaryStatus> findById(String email);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

findByEmail이 낫지 않을까요?

Suggested change
Optional<StudentTemporaryStatus> findById(String email);
Optional<StudentTemporaryStatus> findByEmail(String email);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 처음에 findByEmail로 했는데, 현재 key값인 email은 Id로 해야만 데이터를 찾을 수 있더라고요 ㅋㅋ

Optional<StudentTemporaryStatus> findByAuthToken(String authToken);

void deleteById(String email);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기에는 안 떠있네요 왜지???!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!

if (student.getUser().getNickname() != null) {
userRepository.findByNickname(student.getUser().getNickname())
private void validateDataExist(StudentRegisterRequest request) {
userRepository.findByEmail(request.email())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

findBy를 사용한 이유가 있었군요👀

@@ -51,12 +55,13 @@ public class UserService {
@Transactional
public UserLoginResponse login(UserLoginRequest request) {
User user = userRepository.getByEmail(request.email());
Optional<StudentTemporaryStatus> studentTemporaryStatus = studentRedisRepository.findById(request.email());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

이 로직의 경우는 getByEmail을 사용해서 예외처리 해주는 건 어떨까요?

Copy link
Contributor Author

@kwoo28 kwoo28 Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일반적으로 Repository에서 getBy를 통해 예외처리를 하는 상황은 "데이터를 찾을 수 없습니다."라는 일반적인 예외를 발생시킬때 사용하는것같습니다. 하지만 현재 "미인증 상태입니다. 아우누리에서 인증메일을 확인해주세요"라는 예외처리를 내야 하는 상황인데 이걸 Repository에 구현하는건 너무 사소한 부분까지 Repository계층에서 책임을 맡게되는것같아 계층의 경계가 모호해지는것같아서 서비스계층에서 예외처리 했습니다. 이 부분에 대해 혹시 어덯게 생각하시나요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repository에서 이를 처리한다면, 혹시나 나중에 findById를 쓰게 되는 메소드가 생긴다면 문제가 생길 수도 있겠네요.
코드는 확장성을 고려해서 짜는 것이 중요하니까요..!
저는 혹시나 id를 못 찾는 경우를 생각해서 예외 관련해서 말씀드려봤답니다🤔

@@ -121,4 +121,4 @@ void delete() {
}
dataInitializer.clear();
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

여기도 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AcceptanceTest는 왜 커밋에 올라간거지....ㅋㅋ 일단 고치겠습니다 감사합니다!

@@ -72,4 +72,4 @@ naver:

OPEN_API_KEY_PUBLIC: testck

OPEN_API_KEY_TMONEY: testck
OPEN_API_KEY_TMONEY: testck
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

마지막!!

Copy link
Contributor

@duehee duehee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿! 의견 반영 감사합니당
말씀 주신 부분에서는 의견 달아봤으니 확인해주세요~

@@ -51,12 +55,13 @@ public class UserService {
@Transactional
public UserLoginResponse login(UserLoginRequest request) {
User user = userRepository.getByEmail(request.email());
Optional<StudentTemporaryStatus> studentTemporaryStatus = studentRedisRepository.findById(request.email());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repository에서 이를 처리한다면, 혹시나 나중에 findById를 쓰게 되는 메소드가 생긴다면 문제가 생길 수도 있겠네요.
코드는 확장성을 고려해서 짜는 것이 중요하니까요..!
저는 혹시나 id를 못 찾는 경우를 생각해서 예외 관련해서 말씀드려봤답니다🤔

Copy link
Contributor

@seongjae6751 seongjae6751 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 크게 수정할 점이 보이지 않네요!
고생 많으셨습니다.

  • 전에는 왜 안 됐던 것인지 혹시 아셨나요?

@RedisHash(value = "StudentTemporaryStatus")
public class StudentTemporaryStatus {

private static final long CACHE_EXPIRE_SECOND = 60 * 60 * 10L;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 인증번호를 받는 형식이 아니라 저는 괜찮을 수도 있을 것 같아요
일반적으로 인증번호는 시간을 짧게 하고 저렇게 메일로 보내서 접속하면 인증되게 하는 방식은 엄청 길게 주더라구요
(얼마전에 microsoft 관련해서도 까먹고 있다가 6개월 만에 가서 받았는데 됐음)

@kwoo28
Copy link
Contributor Author

kwoo28 commented Jul 10, 2024

저는 크게 수정할 점이 보이지 않네요! 고생 많으셨습니다.

  • 전에는 왜 안 됐던 것인지 혹시 아셨나요?

인증시간이 지나도 보조인덱스인 @indexed 필드는 자동삭제 안되는 문제였습니다., 근데 지금보니 그 부분 해결하는걸 깜빡했네요; 감사합니다..큰일날뻔했네요

@kwoo28 kwoo28 merged commit baeb24e into develop Jul 15, 2024
3 checks passed
@kwoo28 kwoo28 deleted the feature/544-student-register-expired branch July 15, 2024 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
기능 새로운 기능을 개발합니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[유저] 이메일 인증 시간 끝나면 회원가입 어떻게 할 것인지
3 participants